package 类加载器;

import suo.Main;

public class ClassLoaderDemo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        // 获取系统类加载器（Application ClassLoader）
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println("应用类加载器: " + appClassLoader);
        Class<?> aClass = appClassLoader.loadClass("suo.Main");
        Main o = (Main) aClass.newInstance();
        o.run();
        System.out.println(Main.i);
        // 获取扩展类加载器

        ClassLoader extClassLoader = appClassLoader.getParent();
        System.out.println("扩展类加载器: " + extClassLoader);

        // 获取启动类加载器（Bootstrap ClassLoader，由 C++ 实现，返回 null）
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();
        System.out.println("启动类加载器: " + bootstrapClassLoader);

        // 测试类加载过程
        Class<?> clazz = ClassLoaderDemo.class;
        System.out.println("ClassLoaderDemo 的类加载器: " + clazz.getClassLoader());
    }
}
